package controller;

import GestureRecognition.Slide;
import camera.SkinBasedCamera;
import insurface.InteractiveSurface;
import java.util.Arrays;

public class SkinBasedController extends Controller {

    public static int[] ty;
    Slide sl;

    public SkinBasedController(int CAM_NUM1, int CAM_NUM2, InteractiveSurface ins) {
        super(CAM_NUM1, CAM_NUM2, ins);
        int im1 = ins.initializeCamera(CAM_NUM1);
        int im2 = ins.initializeCamera(CAM_NUM2);
        cam1 = new SkinBasedCamera(CAM_NUM1, CAM_FOV, im1);
        cam2 = new SkinBasedCamera(CAM_NUM2, CAM_FOV, im2);
        th1 = new Thread(cam1);
        th2 = new Thread(cam2);
    }

    @Override
    public void run() {
        th1.start();
        th2.start();
        double theta, beeta, gamma, delta;
        int y1, y2;
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        while (camActive) {
           // System.out.println("while in sbc");
            inSurface.setCamera(((SkinBasedCamera) cam1).imTemp, ((SkinBasedCamera) cam1).skinTemp, ((SkinBasedCamera) cam1).IMAGE_NO);
            inSurface.setCamera(((SkinBasedCamera) cam2).imTemp, ((SkinBasedCamera) cam2).skinTemp, ((SkinBasedCamera) cam2).IMAGE_NO);
            beeta = cam1.getTheta();
            theta = cam2.getTheta();
            delta = Math.toRadians(90) - beeta;
            gamma = Math.toRadians(90 - CAM_FOV) + theta;
            if (theta < Math.toRadians(1) || beeta < Math.toRadians(1)) {
                ty = new int[2];
                ty[0] = -10;
                ty[1] = -10;
            } else {
                ty = coFind.getCoordinate(1, delta, gamma);
            }
            //sl.identifyGestureType(ty, ty);
            inSurface.setXY(ty[0], ty[1]);

            if (gettingLast) {
                y1 = cam1.getY();
                y2 = cam2.getY();


                if (count >= 50) {
                    setYLast();
                } else {
                    yVal1[count] = y1;
                    yVal2[count] = y2;
                    count++;
                }
            }
        }
    }
}
